Creating a Circle

This example demonstrates how to create a circle, set its properties, and then fly to it. This example uses the ICreator80 (CreatePosition, CreateColor, CreateCircle, CreateMessage), INavigate80 (FlyTo), IPosition80 (Copy, Pitch), IColor80, ITerrainRegularPolygon80  (Radius, Message), IFillStyle80 (Color) and ITerraExplorerMessage80 (ID) properties and methods.

 

private void CreateCircle()

        {

            string tMsg = String.Empty;

            IPosition80 cPos = null;

            IColor80 cFillColor = null;

            ITerrainRegularPolygon80 cCircle = null;

            ITerraExplorerMessage80 cMessage = null;

 

            try

            {

                //

                // A. Instantiate TerraExplorer Object

                //

                var SGWorld = new SGWorld80();

 

                //

                // B.  Create position for circle

                //

                // B1. Set position input parameters (San Francisco shore)

                double dXCoord = -122.49460;

                double dYCoord = 37.78816;

                double dAltitude = 100.0;

                AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE;

                double dYaw = 0.0;

                double dPitch = 0.0;

                double dRoll = 0.0;

                double dDistance = 5000;

 

                // B2. Create Position

                cPos = SGWorld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);

 

                //

                // C. create FillColor for circle

                //

                {

                    // C1. Set fill color input params - RGB and Alpha

                    int nRed = 0;

                    int nGreen = 255;

                    int nBlue = 0;

                    int nAlpha = 0x7F; // 50% opacity

 

                    // C2. Create fill color

                    cFillColor = SGWorld.Creator.CreateColor(nRed, nGreen, nBlue, nAlpha);

                }

 

                //

                // D. Create circle using created position and fill color (for line color use Abgr uint value)

                //

                {

                    // D1. Set circle input params

                    uint nLineColor = 0xFFFF0000;   // Abgr value - Solid blue

                    double dCircleRadius = 200;     // in meters

 

                    // C2. Create circle

                    cCircle = SGWorld.Creator.CreateCircle(cPos, dCircleRadius, nLineColor, cFillColor, string.Empty, "Circle");

                }

 

                //

                // E. Get and change circle properties

                //

                {

                    // E1. Get & Set circle radius

                    double dNewCircleRadius = 300;

                    double dCurrentCircleRadius = cCircle.Radius; // Get circle radius

                    cCircle.Radius = dNewCircleRadius;            // Set new circle radius 

 

                    // E2. Get fill style and change its properties

                    uint nRGB_Red = 0xFF0000;  // uing Rgb - Red color

                    double dAlpha = 0.2;       // 80% transparent

                    var cFillStyle = cCircle.FillStyle;

                    cFillStyle.Color.FromRGBColor(nRGB_Red);

                    cFillStyle.Color.SetAlpha(dAlpha);

                }

 

                //

                // F. Add Message to created circle

                //

                {

                    // F1. Set message input parameters

                    MsgTargetPosition eMsgTarget = MsgTargetPosition.MTP_POPUP;

                    string tMessage = "Hello Circle";

                    MsgType eMsgType = MsgType.TYPE_TEXT;

                    bool bIsBringToFront = true;

 

                    // F2. Create message and add to circle

                    cMessage = SGWorld.Creator.CreateMessage(eMsgTarget, tMessage, eMsgType, bIsBringToFront);

                    cCircle.Message.MessageID = cMessage.ID;

                }

 

                //

                // G. FlyTo created circle

                //

                {

                    var cFlyToPos = cPos.Copy();

                    cFlyToPos.Pitch = -89.0; // Set camera to look downward on circle

                    SGWorld.Navigate.FlyTo(cFlyToPos, ActionCode.AC_FLYTO);

                }

            }

            catch (Exception ex)

            {

                tMsg = String.Format("CreateCircleButton_Click Exception: {0}", ex.Message);

                MessageBox.Show(tMsg);

            }

        }